/** $Id: JMapUnitTest.java 63 2010-02-14 13:52:34Z aaron.day $ */
package org.crazydays.gameplan.map.swing;


import java.awt.Dimension;
import java.awt.Graphics;

import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.map.GameMap;
import org.crazydays.gameplan.map.Geometry;
import org.crazydays.gameplan.map.GridType;

/**
 * JMapUnitTest
 */
public class JMapUnitTest
{
    /**
     * Test constructor.
     */
    @Test
    public void testConstructor()
    {
        // objects
        GameMap gameMap = new GameMap("map");

        // test
        JMap component = new JMap(gameMap);

        // verify
        assertEquals("gameMap", gameMap, component.gameMap);
    }

    /**
     * Test getPreferedSize().
     */
    @Test
    public void testGetDimension()
    {
        // objects
        GameMap gameMap =
            new GameMap("map", new Geometry(480, 640, GridType.SQUARE, 20));

        // setup
        JMap component = new JMap(gameMap);

        // test
        Dimension result = component.getPreferredSize();

        // verify
        assertEquals("result.height", (double) 480, result.getHeight(), .0001);
        assertEquals("result.width", (double) 640, result.getWidth(), .0001);
    }

    /**
     * Test paint(Graphics).
     */
    @Test
    public void testPaint()
    {
        // objects
        GameMap gameMap =
            new GameMap("map", new Geometry(480, 640, GridType.SQUARE, 20));

        // mocks
        Graphics graphics = createMock(Graphics.class);

        // setup
        JMap component = new JMap(gameMap);

        // expect
        expect(graphics.drawImage(gameMap.getImage(), 0, 0, null)).andReturn(
            true);

        // replay
        replay(graphics);

        // test
        component.paint(graphics);

        // verify
        verify(graphics);
    }
}
